package com.grass.p019lv.view;

import android.animation.ValueAnimator;
import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import androidx.coordinatorlayout.widget.CoordinatorLayout;
import androidx.core.view.ViewCompat;
import com.androidsa.bttsddka.R;
import com.google.android.material.appbar.AppBarLayout;

/* renamed from: com.grass.lv.view.AppBarZoomBehavior */
public class AppBarZoomBehavior extends AppBarLayout.Behavior {
    private static final float MAX_ZOOM_HEIGHT = 500.0f;
    private boolean isAnimate;
    private int mAppbarHeight;
    private int mLastBottom;
    private float mScaleValue;
    private float mTotalDy;
    private int mViewHeight;
    ValueAnimator valueAnimator;
    private View view;

    public AppBarZoomBehavior(Context context, AttributeSet attributeSet) {
        super(context, attributeSet);
    }

    @Override // com.google.android.material.appbar.AppBarLayout.BaseBehavior, com.google.android.material.appbar.AppBarLayout.Behavior
    public boolean onLayoutChild(CoordinatorLayout coordinatorLayout, AppBarLayout appBarLayout, int i) {
        boolean onLayoutChild = super.onLayoutChild(coordinatorLayout, appBarLayout, i);
        init(appBarLayout);
        return onLayoutChild;
    }

    private void init(AppBarLayout appBarLayout) {
        appBarLayout.setClipChildren(false);
        this.mAppbarHeight = appBarLayout.getHeight();
        View findViewById = appBarLayout.findViewById(R.id.rl_bg_head);
        this.view = findViewById;
        if (findViewById != null) {
            this.mViewHeight = findViewById.getHeight();
        }
    }

    @Override // com.google.android.material.appbar.AppBarLayout.BaseBehavior, com.google.android.material.appbar.AppBarLayout.Behavior
    public boolean onStartNestedScroll(CoordinatorLayout coordinatorLayout, AppBarLayout appBarLayout, View view2, View view3, int i, int i2) {
        this.isAnimate = true;
        return true;
    }

    @Override // com.google.android.material.appbar.AppBarLayout.BaseBehavior, com.google.android.material.appbar.AppBarLayout.Behavior
    public void onNestedPreScroll(CoordinatorLayout coordinatorLayout, AppBarLayout appBarLayout, View view2, int i, int i2, int[] iArr, int i3) {
        if (this.view != null && appBarLayout.getBottom() >= this.mAppbarHeight && i2 < 0 && i3 == 0) {
            zoomHeaderImageView(appBarLayout, i2);
        } else if (this.view == null || appBarLayout.getBottom() <= this.mAppbarHeight || i2 <= 0 || i3 != 0) {
            ValueAnimator valueAnimator2 = this.valueAnimator;
            if (valueAnimator2 == null || !valueAnimator2.isRunning()) {
                super.onNestedPreScroll(coordinatorLayout, appBarLayout, view2, i, i2, iArr, i3);
            }
        } else {
            iArr[1] = i2;
            zoomHeaderImageView(appBarLayout, i2);
        }
    }

    private void zoomHeaderImageView(AppBarLayout appBarLayout, int i) {
        float f = this.mTotalDy + ((float) (-i));
        this.mTotalDy = f;
        float min = Math.min(f, (float) MAX_ZOOM_HEIGHT);
        this.mTotalDy = min;
        float max = Math.max(1.0f, (min / MAX_ZOOM_HEIGHT) + 1.0f);
        this.mScaleValue = max;
        ViewCompat.setScaleX(this.view, max);
        ViewCompat.setScaleY(this.view, this.mScaleValue);
        int i2 = this.mAppbarHeight + ((int) (((float) (this.mViewHeight / 2)) * (this.mScaleValue - 1.0f)));
        this.mLastBottom = i2;
        appBarLayout.setBottom(i2);
    }

    public boolean onNestedPreFling(CoordinatorLayout coordinatorLayout, AppBarLayout appBarLayout, View view2, float f, float f2) {
        if (f2 > 100.0f) {
            this.isAnimate = false;
        }
        return super.onNestedPreFling(coordinatorLayout, (View) appBarLayout, view2, f, f2);
    }

    @Override // com.google.android.material.appbar.AppBarLayout.BaseBehavior, com.google.android.material.appbar.AppBarLayout.Behavior
    public void onStopNestedScroll(CoordinatorLayout coordinatorLayout, AppBarLayout appBarLayout, View view2, int i) {
        recovery(appBarLayout);
        super.onStopNestedScroll(coordinatorLayout, appBarLayout, view2, i);
    }

    private void recovery(final AppBarLayout appBarLayout) {
        if (this.mTotalDy > 0.0f) {
            this.mTotalDy = 0.0f;
            if (this.isAnimate) {
                ValueAnimator duration = ValueAnimator.ofFloat(this.mScaleValue, 1.0f).setDuration(220L);
                this.valueAnimator = duration;
                duration.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
                    /* class com.grass.p019lv.view.AppBarZoomBehavior.C32301 */

                    public void onAnimationUpdate(ValueAnimator valueAnimator) {
                        float floatValue = ((Float) valueAnimator.getAnimatedValue()).floatValue();
                        ViewCompat.setScaleX(AppBarZoomBehavior.this.view, floatValue);
                        ViewCompat.setScaleY(AppBarZoomBehavior.this.view, floatValue);
                        appBarLayout.setBottom((int) (((float) AppBarZoomBehavior.this.mLastBottom) - (((float) (AppBarZoomBehavior.this.mLastBottom - AppBarZoomBehavior.this.mAppbarHeight)) * valueAnimator.getAnimatedFraction())));
                    }
                });
                this.valueAnimator.start();
                return;
            }
            ViewCompat.setScaleX(this.view, 1.0f);
            ViewCompat.setScaleY(this.view, 1.0f);
            appBarLayout.setBottom(this.mAppbarHeight);
        }
    }
}
